#ifndef _LED_H_
#define _LED_H_

#include "Global.h"
#include "SC_GPIO.h"

#define C_RUNHORSE_SPEED   7//12//12

#define P_LED1    DEF_PIN(B,2)
#define M_LED1    DEF_PIN_DIR(B, 2)
#define WPU_LED1  DEF_PIN_WPU(B, 2)

#define P_LED_BK    DEF_PIN(B,3)
#define M_LED_BK    DEF_PIN_DIR(B,3)
#define WPU_LED_BK  DEF_PIN_WPU(B, 3)

#define OPEN_LED()      do{M_LED1=0; P_LED1=0;}while(0)
#define CLOSE_LED()     do{M_LED1=0; P_LED1=1;}while(0)


// #define SET_IN(pin)      do{P_##pin = 1;  M_##pin = 1; WPU_##pin = 1;} while(0)
// #define SET_OUT(pin,hl)  do{M_##pin = 0; P_##pin = hl; WPU_##pin = 0;} while(0)
// #define GET_PIN(pin)    P_##pin
 
#define EN_LED1()       do{SET_OUT(LED1,LOW);}while(0)         
#define DIS_LED1()      do{SET_OUT(LED1,HIGH);}while(0)  
#define LED_ALL_OFF()   DIS_LED1(); 

#define EN_LED_BK()     do{P_LED_BK = LOW;}while(0)
#define DIS_LED_BK()    do{P_LED_BK = HIGH;}while(0)

#define P_BOOST     RB4
#define EN_BOOST()  do{P_BOOST = HIGH;}while(0)
#define DIS_BOOST() do{P_BOOST = LOW;}while(0)

enum
{
    LED1 = 0x01,
    LED2 = 0x02,
    LED3 = 0x04,
    LED4 = 0x08,
    LED5 = 0x10,
    LED6 = 0x20,
    LED7 = 0x40,
    LED8 = 0x80,
};

enum
{
    TOP = 0x01,
    BOTTOM=0x02,
};


typedef struct 
{
    uint8 Buf;
    uint8 ScanIdx;
    uint16 Cnt;
    uint16 TmOn;
    uint16 TmPeriod;
    uint8 Loop;
    void(*FuncCallBack)(void);
}Typedef_LED;


// extern volatile uint16 TimeLedOn;




#define ALL_ON      0xFF
#define ALL_OFF     0x00

#define MODE_NORMAL     0
#define MODE_RUN_HORSE  1

#define TIME_BASE_LED   8

void    initLED(void);
void LED_Set(uint8 buf, uint16 tm_on, uint16 tm_period, uint8 loop,void(*FuncTimerCallBack)(void));
void    LED_Main(void);
uint8   LED_Check(void);
void LED_RunHorse(uint8 speed);


#endif
